<template>
  <div class="home">
    <el-container>
      <el-header height="80px">
        <div>
          <img src="../../assets/dongtai.gif" alt />
          <p>电商后台管理系统</p>
        </div>
        <el-button type="success" @click="logout">返回登录页面</el-button>
      </el-header>
      <el-container>
        <el-aside :width="falg ? '64px' : '200px'">
          <p @click="falg = !falg" v-show="falg == false">|||</p>
          <p @click="falg = !falg" v-show="falg == true">
            <i class="el-icon-more-outline"></i>
          </p>

          <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            :unique-opened="true"
            :collapse="falg"
            :collapse-transition="false"
            router
          >
            <el-submenu :index="item.id+ ''" v-for="item in leftData" :key="item.id">
              <template slot="title">
                <i :class="iconName[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item
                :index="it.path + ''"
                v-for="it in item.children"
                :key="it.id"
                @click="getBreadcrumb(item.authName,it.authName)"
              >
                <i class="el-icon-star-on"></i>
                {{it.authName}}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getMenuList } from "../../api/Home/index"
export default {
  data() {
    return {
      leftData: [], //左侧列表数据
      iconName: {
        "125": "el-icon-user-solid",
        "103": "el-icon-connection",
        "101": "el-icon-s-cooperation",
        "102": "el-icon-s-order",
        "145": "el-icon-loading"
      }, //icon图标
      falg: false //折叠展开开关
    };
  },
  methods: {
    //退出,清除路由信息
    logout() {
      sessionStorage.clear("loginmsg");
      this.$router.push("/login");
    },
    //获取左侧权限列表数据
    async getMenu() {
     let {data:res} = await getMenuList()
      // var { data: res } = await this.$http.get("/menus");
      console.log(res.data);
      this.leftData = res.data;
    },
    //面包屑导航
    getBreadcrumb(one, two) {
      console.log(one, two);
      let obj = {
        oneName: one,
        twoName: two
      };
      sessionStorage.setItem("path", JSON.stringify(obj));
    }
  },
  mounted() {
    this.getMenu();
  }
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .el-container {
    width: 100%;
    height: 100%;
    .el-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: #373d41;
      width: 100%;
      height: 100px;
      div {
        display: flex;
        align-items: center;
        img {
          width: 70px;
          height: 70px;
        }
        p {
          margin-left: 20px;
          font-size: 24px;
          color: white;
          font-weight: 700;
        }
      }
    }
    .el-container {
      display: flex;
      flex: 1;
      justify-content: space-between;
      .el-aside {
        width: 200px;
        background-color: #333744;
        p {
          background: #333744;
          text-align: center;
          color: white;
          font-size: 14px;
          padding: 4px 0;
          letter-spacing: 2px;
        }
      }
      .el-main {
        flex: 1;
        background: #e4f5ef;
      }
    }
  }
}
</style>